package com.bjsxt.controller;

import com.bjsxt.pojo.Admin;
import com.bjsxt.pojo.PageA;
import com.bjsxt.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.sql.Date;

@Controller
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;


    @RequestMapping("/admintc")
    public String admintc(HttpSession session){
        session.invalidate();
        return "redirect:/login.jsp";
    }

    @ResponseBody
    @RequestMapping("/selectAdminController")
    public Admin selectAdminController(String aname, String apwd, HttpSession session){
        Admin admin=adminService.selectAdminSice(aname,apwd);

        session.setAttribute("admin",admin);

        return adminService.selectAdminSice(aname, apwd);
    }

    //分页查询所有
    @ResponseBody
    @RequestMapping("/selectAdminAll")
    public PageA<Admin> selectAdminAll(Integer page,Integer rows){
        return adminService.selectAdminAllSice(page, rows);
    }

    //添加管理员
    @ResponseBody
    @RequestMapping("/insertAdmin")
    public Integer insertAdmin(Admin admin,Integer aid, Integer rid){
        return adminService.insertAdmin(admin,aid,rid);
    }

    //修改
    @ResponseBody
    @RequestMapping("/updateAdmin")
    public Integer updateAdmin(Admin admin,Integer aid,Integer rid){
        return adminService.updateAdmin(admin,aid, rid);
    }

    //删除管理员
    @ResponseBody
    @RequestMapping("/deleteAdmin")
    public Integer deleteAdmin(Integer aid){
        return adminService.deleteAdminSice(aid);
    }
}
